package com.hmdp;

import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class KakaoPayReady {
    public static void main(String[] args) {
        try {
            String secretKey = "DEV8EDC16D2D555672813C6C6C6B56C7B68452B7";
            String url = "https://open-api.kakaopay.com/online/v1/payment/ready";
            URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();

            con.setRequestMethod("POST");
            con.setRequestProperty("Authorization", "DEV_SECRET_KEY " + secretKey);
            con.setRequestProperty("Content-Type", "application/json");

            String jsonInputString = "{\n" +
                    "	\"cid\": \"TC0ONETIME\",\n" +
                    "	\"partner_order_id\": \"partner_order_id\",\n" +
                    "	\"partner_user_id\": \"partner_user_id\",\n" +
                    "	\"item_name\": \"초코파이\",\n" +
                    "	\"quantity\": \"1\",\n" +
                    "	\"total_amount\": \"2200\",\n" +
                    "	\"vat_amount\": \"200\",\n" +
                    "	\"tax_free_amount\": \"0\",\n" +
                    "	\"approval_url\": \"https://developers.kakao.com/success\",\n" +
                    "	\"fail_url\": \"https://developers.kakao.com/fail\",\n" +
                    "	\"cancel_url\": \"https://developers.kakao.com/cancel\"\n" +
                    "}";

            con.setDoOutput(true);
            OutputStream os = con.getOutputStream();
            os.write(jsonInputString.getBytes("UTF-8"));
            os.flush();
            os.close();

            int responseCode = con.getResponseCode();
            System.out.println("Response Code : " + responseCode);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
